<template>
    <el-dialog title="更改任务" :close-on-click-modal="false" append-to-body :visible.sync="visible" lock-scroll
        width="500px">
        <el-row :gutter="15" class="">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="100px"
                label-position="right">
                <template v-if="!loading">

                    <el-col :span="24">
                        <el-form-item label="关联项目" prop="relClassId">
                            <el-select v-model="dataForm.relClassId" placeholder="请选择" clearable
                                :style='{ "width": "100%" }' @change="changeDataList">
                                <el-option v-for="( item, index ) in  relClassIdOptions " :key="index"
                                    :label="item.name" :value="item.F_Id" :disabled="item.disabled"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="开始时间" prop="relClassId">
                            <el-select v-model="dataForm.relClassId" placeholder="请选择" clearable
                                :style='{ "width": "100%" }' @change="changeDataList">
                                <el-option v-for="( item, index ) in  relClassIdOptions " :key="index"
                                    :label="item.name" :value="item.F_Id" :disabled="item.disabled"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="结束时间" prop="relClassId">
                            <el-select v-model="dataForm.relClassId" placeholder="请选择" clearable
                                :style='{ "width": "100%" }' @change="changeDataList">
                                <el-option v-for="( item, index ) in  relClassIdOptions " :key="index"
                                    :label="item.name" :value="item.F_Id" :disabled="item.disabled"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="操作人员" prop="relClassId">
                            <el-select v-model="dataForm.relClassId" placeholder="请选择" clearable
                                :style='{ "width": "100%" }' @change="changeDataList">
                                <el-option v-for="( item, index ) in  relClassIdOptions " :key="index"
                                    :label="item.name" :value="item.F_Id" :disabled="item.disabled"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="一消员" prop="relClassId">
                            <el-select v-model="dataForm.relClassId" placeholder="请选择" clearable
                                :style='{ "width": "100%" }' @change="changeDataList">
                                <el-option v-for="( item, index ) in  relClassIdOptions " :key="index"
                                    :label="item.name" :value="item.F_Id" :disabled="item.disabled"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="批准人" prop="relClassId">
                            <el-select v-model="dataForm.relClassId" placeholder="请选择" clearable
                                :style='{ "width": "100%" }' @change="changeDataList">
                                <el-option v-for="( item, index ) in  relClassIdOptions " :key="index"
                                    :label="item.name" :value="item.F_Id" :disabled="item.disabled"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="推送委托单位通知" prop="description" style="margin-top: 1rem;">
                            <el-input type="textarea" :row="3" v-model="dataForm.description" placeholder="请输入"
                                clearable :style='{ "width": "100%" }' :disabled="selectCheckState">

                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="上传附件" prop="relClassId">
                            <el-select v-model="dataForm.relClassId" placeholder="请选择" clearable
                                :style='{ "width": "100%" }' @change="changeDataList">
                                <el-option v-for="( item, index ) in  relClassIdOptions " :key="index"
                                    :label="item.name" :value="item.F_Id" :disabled="item.disabled"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </template>
            </el-form>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false"> 取 消</el-button>
            <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> 确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>

export default {
    components: {},
    props: [],
    data() {
        return {
            // 选择题答案
            selectCheckState: false,
            selectIndex: 0,
            rightChoice: '',

            checkedCities: [],
            a: [],
            radioAll: [],
            dataFormSubmitType: 0,
            continueBtnLoading: false,
            index: 0,
            prevDis: false,
            nextDis: false,
            allList: [],
            visible: false,
            loading: false,
            btnLoading: false,
            selectDialogVisible: false,
            currTableConf: {},
            addTableConf: {
            },
            //可选范围默认值
            ableAll: {
            },
            tableRows: {
            },

            dataForm: {
                name: '',
                description: '',
                type: '',

            },
            rules:
            {
                name: [
                    {
                        required: true,
                        message: '请输入',
                        trigger: 'blur'
                    }
                ],
                relClassId: [
                    {
                        required: true,
                        message: '请至少选择一个',
                        trigger: 'change'
                    },
                ],
                type: [
                    {
                        required: true,
                        message: '不能为空',
                        trigger: 'change'
                    },
                ],

                aList: [
                    {
                        required: true,
                        message: '',
                        trigger: "blur"
                    }
                ]
            },

            relClassIdOptions: [],

            childIndex: -1,
            isEdit: false,

        }
    },

    watch: {},
    created() {

    },
    mounted() { },
    methods: {

        clearData() {
            this.dataForm.name = '';

            this.dataForm.description = '';
            this.dataForm.type = '';

            this.radioAll = ''
            this.selectCheckState = false
            this.a = []
            this.checkedCities = []
        },
        init() {
            this.visible = true;
            this.$nextTick(() => {

            });

        },




        // 表单提交
        dataFormSubmit(type) {

            this.dataFormSubmitType = type ? type : 0
            this.$refs['elForm'].validate((valid) => {
                if (valid) {
                    this.request()
                }
            })
        },
        request() {
            if (this.dataFormSubmitType == 2) {
                this.continueBtnLoading = true
            } else {
                this.btnLoading = true
            }
            let _data = this.dataList()
            if (!this.dataForm.id) {
                request({
                    url: '/api/example/Question',
                    method: 'post',
                    data: _data
                }).then((res) => {
                    // this.$message({
                    //     message: res.msg,
                    //     type: 'success',
                    //     duration: 1000,
                    //     onClose: () => {
                    //         if (this.dataFormSubmitType == 2) {
                    //             this.$nextTick(() => {
                    //                 this.$refs['elForm'].resetFields();
                    //                 this.clearData()
                    //                 this.initDefaultData()
                    //             })
                    //             this.continueBtnLoading = false
                    //             this.$emit('refreshList', true)
                    //             return
                    //         }
                    //         this.visible = false
                    //         this.btnLoading = false
                    //         this.$emit('refresh', true)
                    //     }
                    // })
                    if (this.dataFormSubmitType == 2) {
                        this.$nextTick(() => {
                            this.$refs['elForm'].resetFields();
                            this.clearData()
                            this.initDefaultData()
                        })
                        this.continueBtnLoading = false
                        this.$emit('refreshList', true)
                        return
                    }
                    this.visible = false
                    this.btnLoading = false
                    this.$emit('refreshFo', true)
                }).catch(() => {
                    this.btnLoading = false
                    this.continueBtnLoading = false
                })
            } else {
                request({
                    url: '/api/example/Question/' + this.dataForm.id,
                    method: 'PUT',
                    data: _data
                }).then((res) => {
                    // this.$message({
                    //     message: res.msg,
                    //     type: 'success',
                    //     duration: 1000,
                    //     onClose: () => {
                    //         if (this.dataFormSubmitType == 2) return this.continueBtnLoading = false
                    //         this.visible = false
                    //         this.btnLoading = false
                    //         this.$emit('refresh', true)
                    //     }
                    // })
                    if (this.dataFormSubmitType == 2) return this.continueBtnLoading = false
                    this.visible = false
                    this.btnLoading = false
                    this.$emit('refreshList', true, 1)
                }).catch(() => {
                    this.btnLoading = false
                    this.continueBtnLoading = false
                })
            }
        },




    },
}

</script>